package com.hbt;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import com.bean.Cliente;
import com.bean.CondicionComercial;
import com.bean.Cotizacion;
import com.bean.ItemCotizacion;
import com.bean.Factura;
import com.bean.ItemFactura;
import com.bean.ItemVenta;
import com.bean.Venta;
import com.bean.OrdenCompra;
import com.bean.ItemOrdenCompra;
import com.bean.ListaPrecios;
import com.bean.ItemListaPrecios;
import com.bean.Proveedor;
import com.bean.Rodamiento;

public class HibernateUtil
{
	 /** The single instance of hibernate SessionFactory */
    private static final SessionFactory sessionFactory;
    
    /**
     * disable contructor to guaranty a single instance
     */
    private HibernateUtil() {}
    
    static
    {
        try
        {
        	 AnnotationConfiguration config = new AnnotationConfiguration();
        
        	 config.addAnnotatedClass(Cliente.class);
        	 config.addAnnotatedClass(CondicionComercial.class);
        	 config.addAnnotatedClass(Proveedor.class);
        	 config.addAnnotatedClass(Rodamiento.class);
           	 config.addAnnotatedClass(ListaPrecios.class);            
             config.addAnnotatedClass(ItemListaPrecios.class);            
        	 config.addAnnotatedClass(Cotizacion.class);
        	 config.addAnnotatedClass(ItemCotizacion.class);
        	 config.addAnnotatedClass(Venta.class);
        	 config.addAnnotatedClass(ItemVenta.class);
        	 config.addAnnotatedClass(OrdenCompra.class);
        	 config.addAnnotatedClass(ItemOrdenCompra.class);
        	 config.addAnnotatedClass(Factura.class);
        	 config.addAnnotatedClass(ItemFactura.class);
 
             sessionFactory = config.buildSessionFactory();
        }
        catch (Throwable ex)
        {
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
 
    public static SessionFactory getSessionFactory()
    {
        return sessionFactory;
    }
}
